﻿using Biomedica.Graphics;
using Biomedica.Propability.StateMachine;
using KinectWindows.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KinectWindows.Nui.Nui.Postures
{
    public class InvirtualBoxPostures : PostureDetectorBase
    {
        public InvirtualBoxPostures(StateContext Context):base(10,Context)
        {
            Range = 0.5f;

        }

        internal void TrackPosture(Vector3 Sholder_Center,Vector3 Lefthand, Vector3 RightHand)
        {
            TrackPosture(new Vector3[] { Sholder_Center,Lefthand,RightHand });
        }

        private bool chekHandsinBound(Vector3 Shoulder_Center, Vector3 Hand)
        {

            float th1 = System.Math.Abs(Shoulder_Center.Z - Hand.Z);
           
            
            if (!Hand.HasValue || !Shoulder_Center.HasValue || !Shoulder_Center.HasValue) return false;
            if (th1<Range) return false; ;// NuiEventManager.PostEvent(new NuiEvent(Messages.WindowMessages.NUI_MSG_LEFT_HAND_IN_INTERACTION_ZONE, JointTemplate));
           
            return true;
        }

        public override void TrackPosture(Vector3[] jointsPos)
        {
            if(chekHandsinBound(jointsPos[0],jointsPos[2])) RaisPostureDetected("Left Hand In Zone");
            if (chekHandsinBound(jointsPos[0], jointsPos[1])) RaisPostureDetected("Right Hand In Zone");

            Reset();
        }

        public float Range { get; set; }
    }
}
